#!/usr/bin/env bash
set -e

status=0

export PATH="${PWD}/bin:$PATH"

rails_version="$(ruby -rubygems -e 'require "bundler"; puts Bundler.load.specs.find {|s| s.name == "activerecord" }.version')"

for db in sqlite3 mysql mysql2 postgres; do
  [[ "$rails_version" = 3.0 && $db = "mysql2" ]] && continue
  [[ "$rails_version" > 5.0 && $db = "mysql" ]] && continue

  printf "\e[1;33m[DB] %s\e[m\n" "$db"
  spec_files="spec"
  [[ $db != "sqlite3" ]] && spec_files="spec/finders/active_record_spec.rb"
  echo "rspec $spec_files"
  DB="$db" rspec -r fake_rubygems "$spec_files" || status="$?"
done

exit $status
